"""
>>> from pollster.models import *
>>> from datetime import datetime
>>> PAST = datetime(2005, 1, 1)
>>> FUTURE = datetime(2050, 1, 1)

# Create a Poll
>>> poll = Poll(question="What's your favorite web-framework?")
>>> poll.save()

# There should be no open polls.
>>> Poll.objects.open()
[]
>>> Poll.objects.newest() == None
True

# Give the poll a start date in the past (open it).
# No end date is specified.
>>> poll.start = PAST
>>> poll.save()
>>> Poll.objects.open()
[<Poll: What's your favorite web-framework?>]
>>> Poll.objects.newest()
<Poll: What's your favorite web-framework?>

# Give the poll an end date in the future.
# It should stil be open.
>>> poll.end = FUTURE
>>> poll.save()
>>> Poll.objects.open()
[<Poll: What's your favorite web-framework?>]

# End the poll.
>>> poll.end = datetime.now()
>>> poll.save()
>>> Poll.objects.open()
[]

# Should be able to re-open it by removing the end date.
>>> poll.end = None
>>> poll.save()
>>> Poll.objects.open()
[<Poll: What's your favorite web-framework?>]

# Create another open Poll.
>>> poll2 = Poll(question="Do you like chicken fingers?", start=datetime.now(), end=FUTURE)
>>> poll2.save()
>>> Poll.objects.open()
[<Poll: Do you like chicken fingers?>, <Poll: What's your favorite web-framework?>]

# Poll2 should be the newest.
>>> Poll.objects.newest()
<Poll: Do you like chicken fingers?>

# Add some choices to Poll #1
>>> Choice(poll=poll, choice="Ruby on rails", position=1).save()
>>> Choice(poll=poll, choice="Django", position=0).save()
>>> Choice(poll=poll, choice="Cake PHP", position=2).save()
>>> poll.choice_set.all()
[<Choice: Django>, <Choice: Ruby on rails>, <Choice: Cake PHP>]
>>> django = poll.choice_set.all()[0]
>>> rails = poll.choice_set.all()[1]
>>> cake = poll.choice_set.all()[2]

# Test the vote counting
>>> django.vote_set.count()
0
>>> Vote(choice=django).save()
>>> django.vote_set.count()
1
>>> Vote(choice=django).save()
>>> Vote(choice=django).save()
>>> Vote(choice=django).save()
>>> django.vote_set.count()
4
>>> Vote(choice=rails).save()
>>> rails.vote_set.count()
1

# Test ``get_percent`` helper.
>>> django.get_percent()
80
>>> rails.get_percent()
20
>>> cake.get_percent()
0
>>> no_votes = Choice(poll=poll2, choice="Yes, I love chicken fingers.")
>>> no_votes.save()
>>> no_votes.get_percent()
0

# should be able to tag polls and then filter by tag.
>>> poll.tags = "web, frameworks, programming, geek"
>>> poll.save()
>>> Poll.objects.open(filters={'tags__icontains':'web'})
[<Poll: What's your favorite web-framework?>]


# Testing views
>>> from django.test.client import Client
>>> c = Client()
>>> django.vote_set.count()
4

# Should be able to vote:
>>> response = c.post(poll.get_submit_url(), {'poll':poll.id, 'choices':django.id})
>>> django.vote_set.count()
5

# Raise 404 if making an invalid vote:
>>> response = c.post(poll.get_submit_url(), {'poll':12345, 'choices':django.id})
>>> response.status_code
404

# Should not be able to vote again:
>>> response = c.post(poll.get_submit_url(), {'polls':poll.id, 'choices':django.id})
>>> response.status_code
404

"""